package conf

import (
	"fmt"
	"gopkg.in/ini.v1"
	"strings"
)
var(
	DataPath string
	Port string

	AppMode string
	HttpPort string
	RedisAddr string
	RedisPw string
	Db string
	DbHost string

	DbPort string
	DbUser string
	DbPaw string
	DbName string

)
func Init(){

	file , err := ini.Load("./conf/conf.ini")
	if err != nil{
		fmt.Println("配置文件错误")
	}
	LoadServer(file)
	LoadMysql(file)
	//"root:yourpassword@(127.0.0.1)/test?charset=utf8mb4&loc=Local")
	path := strings.Join([]string{DbUser,":",DbPaw,"@tcp(",DbHost,":",DbPort,")/",DbName,"?charset=utf8mb4&parseTime=true"},"")
	fmt.Println(path)
	//time.Sleep(time.Second*100)
	DataPath = path
	//model.Datebase(path)
	fmt.Println(path)
	LoadRedis(file)
	Port = file.Section("service").Key("HttpPort").String()
}

func LoadServer(file *ini.File){
	AppMode = file.Section("service").Key("AppMode").String()
	HttpPort = file.Section("service").Key("HttpPort").String()
}

func LoadMysql(file *ini.File){
	Db = file.Section("mysql").Key("Db").String()
	DbHost = file.Section("mysql").Key("DbHost").String()
	DbPort = file.Section("mysql").Key("DbPort").String()
	DbUser = file.Section("mysql").Key("DbUser").String()
	DbPaw = file.Section("mysql").Key("DbPaw").String()
	DbName = file.Section("mysql").Key("DbName").String()
}

func LoadRedis(file *ini.File){
	RedisAddr = file.Section("redis").Key("RedisAddr").String()
	RedisPw = file.Section("redis").Key("RedisPw").String()

}
